package com.lq.demo.demo.mode.limit;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class CallerRunning {


    // to store the log  data
    static public   StringBuffer sb = new StringBuffer();
    /**
     * @param args
     */
    public static void main(String[] args) {


        long startMills = System.currentTimeMillis();
        long nowMills = startMills ;

        //call a method 60000 times in 1 minute
        CheckCalledTimesInPeriod called = new CheckCalledTimesInPeriod(1, startMills, 60000);

        //to log the running time
        Calendar c = Calendar.getInstance();
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        sb.append("begin time is = "+format.format(c.getTime())+"\r\n");

        //test run  in 6 second
        while(nowMills<=(startMills+6000))
        {

            nowMills = System.currentTimeMillis();
            called.execute();
        }

        //to write the log to txt
        Calendar d = Calendar.getInstance();
        sb.append("end time is = "+format.format(d.getTime())+"\r\n");
        writeTxt("C:\\test.txt", sb.toString());
    }


    public static void writeTxt(String filePath, String content){

        try {
            File f = new File(filePath);
            if (!f.exists()) {
                f.createNewFile();// 不存在则创建
            }
            BufferedWriter output = new BufferedWriter(new FileWriter(f));
            output.write(content);
            output.close();
        } catch (Exception e) {
            e.printStackTrace();

        }
    }


}